<template>
    <div>
        <router-link tag="div" to="/" class="header-abs" v-show="showABS"><div class="iconfont header-abs-back">&#xe624;</div></router-link>
        <div class="header-fixed" v-show="!showABS" :style="opacityStyle">
            <router-link tag="div" to="/" class="iconfont header-fixed-back">&#xe624;</router-link>
            <div>景点详情</div>
        </div>
    </div>
</template>

<script>
export default {
    name: 'DetailHeader',
    data () {
        return {
            showABS: true,
            opacityStyle: {
                opacity: 0
            }
        }
    },
    methods: {
        handleScroll () {
            const top =document.documentElement.scrollTop
            if(top>60){
                let opacity = top / 140//实现渐隐渐现效果
                opacity = opacity > 1 ? 1 : opacity
                this.opacityStyle = { opacity }
                this.showABS = false
            }else{
                this.showABS = true
            }
        }
    },
    mounted () {
        window.addEventListener('scroll',this.handleScroll)
    },
    destroyed () {
        window.removeEventListener('scroll',this.handleScroll)
    }
    /*activated () {
        window.addEventListener('scroll',this.handleScroll)
    },
    deactivated () {
        window.removeEventListener('scroll',this.handleScroll)
    }*/
}
</script>

<style lang="stylus" scoped>
    @import '~@/assets/styles/varibles.styl'
    .header-abs
        position: absolute
        left: 0.2rem
        top: 0.2rem
        width: 0.7rem
        height: 0.7rem
        line-height: .7rem
        text-align: center
        border-radius: .35rem
        background: rgba(0,0,0,.8)
        .header-abs-back
            padding-right: .05rem
            color: #fff
            font-size: .4rem
    .header-fixed
        z-index: 2
        position: fixed
        left: 0
        top: 0
        right: 0
        height: .86rem
        line-height: .86rem
        text-align: center
        color: #fff
        font-size: .32rem
        background: $bgColor
        .header-fixed-back
            position: absolute
            left: 0
            top: 0
            width: .64rem
            text-align: center
            font-size: .4rem
            color: #fff
</style>
